#region Copyright
// Copyright (c) 2010, Kazi Manzur Rashid <kazimanzurrashid@gmail.com>.
// This source is subject to the Microsoft Public License. 
// See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL. 
// All other rights reserved.
#endregion

namespace LiveWriter.Plugins.SyntaxHighlighter
{
    using System;
    using System.Windows.Forms;

    using WindowsLive.Writer.Api;

    internal partial class DefaultSetting : Form
    {
        public DefaultSetting()
        {
            InitializeComponent();
            cboLanguages.Load(SupportedSettings.Languages);
        }

        public DefaultSetting(IProperties properties) : this()
        {
            Properties = properties;
            LoadProperties();
        }

        protected IProperties Properties { get; private set; }

        private void LoadProperties()
        {
            cboLanguages.SetSelectedIndex(Properties.Language());
            chkAutoLink.Checked = Properties.AutoLinks();
            chkCollapse.Checked = Properties.Collapse();
            chkSmartTabs.Checked = Properties.SmartTabs();
            chkGutter.Checked = Properties.Gutter();
            chkToolbar.Checked = Properties.Toolbar();
            chkHtmlScript.Checked = Properties.HtmlScript();
            updTabSize.Value = Properties.TabSize();
        }

        private void SaveProperties()
        {
            Properties.Language(((Pair)cboLanguages.SelectedItem).Key);
            Properties.AutoLinks(chkAutoLink.Checked);
            Properties.Collapse(chkCollapse.Checked);
            Properties.SmartTabs(chkSmartTabs.Checked);
            Properties.Gutter(chkGutter.Checked);
            Properties.Toolbar(chkToolbar.Checked);
            Properties.HtmlScript(chkHtmlScript.Checked);
            Properties.TabSize(Convert.ToInt32(updTabSize.Value));
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            SaveProperties();
            DialogResult = DialogResult.OK;
            Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
            Close();
        }
    }
}